﻿using Domain;
using Domain.Models;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Server.HttpSys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TouchSocket.Core;

namespace Application.App.Command
{
    public class GoOutOfWine:IRequest<Result>
    {
        public string device { get; set; }

        public string returnUrl { get; set; }
        /// <summary>
        /// 数量
        /// </summary>
        public int num { get; set; }
    }
    public class GoOutOfWineHandle : IRequestHandler<GoOutOfWine, Result>
    {
        private readonly IMediator mediator;
        public GoOutOfWineHandle(IMediator mediator)
        {
            this.mediator = mediator;
        }
        public async Task<Result> Handle(GoOutOfWine request, CancellationToken cancellationToken)
        {
            if (!Consts.devices.ContainsKey(request.device))
            {
                return Result.FromError("当前设备不在线");
            }

            Consts.devices[request.device].returnUrl = request.returnUrl;
            var oow = new OutOfWineCommand() { ChannelNum = 1, DeviceId = request.device, OutOfWineNum = request.num };
            await mediator.Send(oow);
            return Result.Success;
        }
    }

}
